import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
class Register_Operation:

    @pytest.fixture(scope="module")
    def driver(self):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        yield driver
        driver.quit()
    @pytest.fixture(scope='function')
    def register_page(self,driver,username,password,re_password):
        driver.get("http://localhost:90/toregister.html")
        # 获取账号输入框
        driver.find_element(By.ID, 'username').send_keys(username)
        # 获取密码输入框
        driver.find_element(By.ID, 'password').send_keys(password)
        # 获取重复密码输入框
        driver.find_element(By.ID, 'repassword').send_keys(re_password)
        # 获取注册按钮
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        time.sleep(1)
    #判定与断言
    def asserttitle(self,driver,result,expect):
        if result == expect:
            print("通过")
        else:
            print("不通过")
            import os
            if not os.path.exists("demo"):
                os.mkdir("demo")
            driver.save_screenshot("demo/register.png")
            assert result == expect
    #获取title
    def getSuccessResult(self,driver):
        time.sleep(1)
        return driver.title
